package com.david.mydemo.ctl_kafka.controller;

import com.david.mydemo.ctl_kafka.sender.KafkaSender;
import com.david.mydemo.framework.annotation.MySysLog;
import com.david.mydemo.util.DateUtils;
import com.david.mydemo.util.MyConstants;
import com.david.mydemo.util.MyResponse;
import com.david.mydemo.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping(value = "/kafka")
@Api(tags = "Kafka Controller")
public class KafkaController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @Autowired
    private KafkaSender kafkaSender;

    @RequestMapping(value = "/sendMessage")
    @ApiOperation(value = "发送kafka消息")
    @MySysLog(operate = MyConstants.OPERATE_COMMON, content = "发送kafka消息", module = MyConstants.MODULE_COMMON)
    public MyResponse sendMessage() {
        kafkaSender.sendMessage("测试消息：" + DateUtils.dateTimeNow());
        return new MyResponse().success();
    }

}
